﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Storage.Streams;
using WinRTToolkit.IO;

namespace WinRTToolkit.Storage
{
    public static class IsolatedStorageStaticHelper
    {
        #region Static Members

        private static IsolatedStorageHelper _helper;

        #endregion

        #region Constructor

        static IsolatedStorageStaticHelper()
        {
            SelectScope(IsolatedStorageScope.LocalFolder);
        }

        #endregion

        #region Scope Selection

        public static void SelectScope(IsolatedStorageScope scope)
        {
            _helper = new IsolatedStorageHelper(scope);
        }

        #endregion

        #region Folder

        public async static Task<StorageFolder> GetFolder(string path)
        {
            return await _helper.GetFolder(path);
        }

        public async static Task<bool> FolderExists(string path)
        {
            return await _helper.FolderExists(path);
        }

        public async static Task<IEnumerable<StorageFolder>> GetRootFolders()
        {
            return await _helper.GetRootFolders();
        }

        public async static Task<IEnumerable<StorageFolder>> GetFolders(string path)
        {
            return await _helper.GetFolders(path);
        }

        public async static Task<IEnumerable<StorageFolder>> GetFolders(StorageFolder folder)
        {
            return await _helper.GetFolders(folder);
        }

        public async static Task<StorageFolder> CreateFolder(string path)
        {
            return await _helper.CreateFolder(path);
        }

        public async static Task<bool> DeleteFolder(string path)
        {
            return await _helper.DeleteFolder(path);
        }

        public async static Task<bool> DeleteFolder(StorageFolder folder)
        {
            return await _helper.DeleteFolder(folder);
        }

        #endregion

        #region File

        public async static Task<StorageFile> GetFile(string path)
        {
            return await _helper.GetFile(path);
        }

        public async static Task<StorageFile> GetFile(string path, FileMode fileMode)
        {
            return await _helper.GetFile(path, fileMode);
        }

        public async static Task<bool> FileExists(string path)
        {
            return await _helper.FileExists(path);
        }

        public async static Task<IEnumerable<StorageFile>> GetFiles(string path)
        {
            return await _helper.GetFiles(path);
        }

        public async static Task<IEnumerable<StorageFile>> GetFiles(StorageFolder folder)
        {
            return await _helper.GetFiles(folder);
        }

        public async static Task<StorageFile> CreateFile(string path, bool overrideExisting = false)
        {
            return await _helper.CreateFile(path, overrideExisting);
        }

        public async static Task<IRandomAccessStream> OpenRead(string path)
        {
            return await _helper.OpenRead(path);
        }

        public async static Task<IRandomAccessStream> OpenRead(StorageFile file)
        {
            return await _helper.OpenRead(file);
        }

        public async static Task<IRandomAccessStream> OpenWrite(string path, FileMode fileMode)
        {
            return await _helper.OpenWrite(path, fileMode);
        }

        public async static Task<IRandomAccessStream> OpenWrite(StorageFile file, OpenMode openMode)
        {
            return await _helper.OpenWrite(file, openMode);
        }

        public async static Task<bool> DeleteFile(string path)
        {
            return await _helper.DeleteFile(path);
        }

        public async static Task<bool> DeleteFile(StorageFile file)
        {
            return await _helper.DeleteFile(file);
        }

        public async static Task<T> LoadObject<T>(string path)
        {
            return await _helper.LoadObject<T>(path);
        }

        public async static Task<T> LoadObject<T>(StorageFile file)
        {
            return await _helper.LoadObject<T>(file);
        }

        public async static Task<bool> SaveObject<T>(T item, string path)
        {
            return await _helper.SaveObject<T>(item, path);
        }

        public async static Task<bool> SaveStream(string path, Stream stream)
        {
            return await _helper.SaveStream(path, stream);
        }

        public async static Task<DateTimeOffset> GetDateModified(StorageFile file)
        {
            return await _helper.GetDateModified(file);
        }

        public async static Task<BasicProperties> GetBasicProperties(StorageFile file)
        {
            return await _helper.GetBasicProperties(file);
        }

        #endregion
    }
}
